@echo off
setlocal enabledelayedexpansion

if "%1"=="" (
    echo Usage:
    echo   issue.bat add ^<issueNO^>    - Add issue demo to build
    echo   issue.bat clear           - Clear all issue configurations
    echo   issue.bat new ^<typeName-issueNO-desc^>    - create new issue demo
    echo   issue.bat buildall    - build demos hap with all issues
    echo   issue.bat build ^<issueNO^>    - build demos hap with specified issues
    exit /b 1
)

if "%1"=="add" (
    if "%2"=="" (
        echo Error: issueNO is required
        echo Example: issue.bat add 20250001
        exit /b 1
    )
    echo Adding issue demo %2...
    call hvigorw issueAdd -p issueNO=%2
    call ohpm install --all --registry https://ohpm.openharmony.cn/ohpm/ --strict_ssl false
    call hvigorw --sync
    exit /b 0
)

if "%1"=="clear" (
    echo Clearing issue configurations...
    call hvigorw issueClear
    call ohpm install --all --registry https://ohpm.openharmony.cn/ohpm/ --strict_ssl false
    call hvigorw --sync
    exit /b 0
)

if "%1"=="new" (
    if "%2"=="" (
        echo Error: demoname is required
        echo Example: issue.bat new ArkUI-20250001-test
        exit /b 1
    )
    echo new issue demo %2...
    call hvigorw generateModule -p demoname=%2
    call ohpm install --all --registry https://ohpm.openharmony.cn/ohpm/ --strict_ssl false
    call hvigorw --sync
    exit /b 0
)

if "%1"=="buildall" (
    echo execute clear issue demos....
    call hvigorw issueClear
    echo execute add all issue demos....
    call hvigorw issueAddAll
    echo execute install hars....
    ohpm install --all --registry https://ohpm.openharmony.cn/ohpm/ --strict_ssl false
    call hvigorw --sync
    echo execute build hap....
    call hvigorw --mode module -p module=default@default -p product=default assembleHap
    exit /b 0
)

if "%1"=="build" (
    if "%2"=="" (
        echo Error: issueNO is required
        echo Example: issue.bat build 20250001
        exit /b 1
    )
    echo execute clear issue demos....
    call hvigorw issueClear
    echo execute add issue demo %2...
    call hvigorw issueAdd -p issueNO=%2
    echo execute install hars....
    ohpm install --all --registry https://ohpm.openharmony.cn/ohpm/ --strict_ssl false
    call hvigorw --sync
    echo execute build hap....
    call hvigorw --mode module -p module=default@default -p product=default assembleHap
    exit /b 0
)

echo Error: Unknown command '%1'
echo Valid commands are: add, clear
exit /b 1 